package com.xindaoapp.happypet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;

import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.utils.CommonUtil;

public class FaceAdapter extends BaseAdapter {
    private final Context context;
    private final int[] list;

    public FaceAdapter(Context context, int[] list) {
        super();
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.singleexpression, null);
            holder = new ViewHolder();
            holder.icon = (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.icon.setImageResource(list[position]);
        LayoutParams params =
                new LayoutParams(CommonUtil.dip2px(context, 170) / 3, CommonUtil.dip2px(context,
                        170) / 3);
        holder.icon.setLayoutParams(params);
        return convertView;
    }

    class ViewHolder {
        ImageView icon;
    }

}
